package com.itheima.service.impl;

import com.aliyun.vod.upload.common.MD5Util;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 后台用户业务实现类
 * @Author: hsp
 * @Date: 2022/11/18-11-18-16:41
 * @Description: com.itheima.service.impl
 * @version: 1.0.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 根据账号和密码查询用户
     * @param username
     * @param password
     * @return
     */
    @Override
    public User login(String username, String password) {

        //1. 前端传过来的密码进行加密
        String passwordWithMD5 = MD5Util.md5(password);

        //2. 根据账户和加密后的密码查询用户表
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>();
        wrapper.eq(User::getUsername, username).eq(User::getPassword, passwordWithMD5);

        //3. 返回查询结果
        return userMapper.selectOne(wrapper);
    }
}
